package com.enniu.alipay.api.data.config;

import java.util.HashMap;
import java.util.Map;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;

import com.enniu.alipay.api.data.util.DynamicDataSource;

@Configuration
public class DataSourceDynamic {

	@Bean(name = "dynamicDatasource")
	@DependsOn({ "dataSource1", "dataSource" })
	public DynamicDataSource dynamicDatasource() {
		DynamicDataSource dynamicDataSource = new DynamicDataSource();
		dynamicDataSource.setDefaultTargetDataSource(dataSource);
		Map<Object, Object> mapper = new HashMap<Object, Object>();
		mapper.put("dataSource", dataSource);
		mapper.put("dataSource1", dataSource1);
		dynamicDataSource.setTargetDataSources(mapper);
		return dynamicDataSource;
	}
	
	@Autowired
	@Qualifier("dataSource")
	private DataSource dataSource;
	@Autowired
	@Qualifier("dataSource1")
	private DataSource dataSource1;

}
